package com.manager.devicemanager.controller;

import com.manager.devicemanager.entity.BoardTemplate; // 需确保该实体类存在
import com.manager.devicemanager.service.IBoardTemplateService; // 需确保该服务接口存在
import com.manager.devicemanager.vo.PageVO; // 需确保该分页对象类存在
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.manager.devicemanager.common.Result; // 需确保该统一响应类存在
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wpf
 * @since 2025-05-29
 */
@RestController
@RequestMapping("/boardTemplate")
public class BoardTemplateController {

    @Autowired
    private IBoardTemplateService boardTemplateService;

    /**
     * 带条件筛选和排序功能的分页查询接口
     * @param pageVO 分页查询条件对象，包含页码、每页数量、查询条件、排序字段和排序方式
     * @return 分页查询结果
     */
    @Operation(summary = "带条件筛选和排序的分页查询")
    @PostMapping("/page")
    public Result<IPage<BoardTemplate>> page(
            @Parameter(description = "分页查询条件对象")
            @RequestBody PageVO<BoardTemplate> pageVO) {
        int pageNum = pageVO.getPageNum();
        int pageSize = pageVO.getPageSize();
        BoardTemplate condition = pageVO.getCondition();
        LambdaQueryWrapper<BoardTemplate> queryWrapper = new LambdaQueryWrapper<>(condition);
        IPage<BoardTemplate> pageResult = boardTemplateService.page(
                new Page<>(pageNum, pageSize), queryWrapper);

        return Result.success(pageResult);
    }


}
